<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">每日充值统计</ui:define>
    <ui:define name="content">
        <h:form>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"
                                         actionListener="#{receiptRechargeStatisticsBean.search}"
                                         rendered="#{receiptRechargeStatisticsBean.isNormal()}"/>
                        <p:commandButton id="reset" value="重置" icon="fa fa-refresh"
                                         actionListener="#{receiptRechargeStatisticsBean.onReset}"
                                         update="@form"
                                         rendered="#{receiptRechargeStatisticsBean.isNormal()}"/>
                        <p:commandButton value="导出" icon="fa fa-arrow-down" ajax="false">
                            <p:dataExporter target="rechargeRecordDataTable" fileName="recharge-record" type="xls"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card ui-g-12">
                            <h1>查询条件</h1>
                            <div class="ui-g-1">
                                <p:outputLabel for="startdate" value="日期"/>
                            </div>
                            <div class="ui-g-5">
                                <p:calendar id="startdate" value="#{receiptRechargeStatisticsBean.$.startDate}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"
                                            readonlyInput="true"/>
                                <span>—</span>
                                <p:calendar id="enddate" value="#{receiptRechargeStatisticsBean.$.endDate}"
                                            styleClass="autoWidthCalendar"
                                            locale="#{constants:get('LOCALE')}"
                                            timeZone="#{constants:get('TIME_ZONE')}"
                                            pattern="#{constants:get('DATE_FORMAT')}"
                                            readonlyInput="true"/>
                            </div>

                            <div class="ui-g-1">
                                <p:outputLabel value="产品名称"/>
                            </div>
                            <div class="ui-g-5">
                                <p:selectOneMenu filter="true"
                                                 filterMatchMode="contains"
                                                 value="#{receiptRechargeStatisticsBean.$.receiptProductId}">
                                    <f:selectItem itemLabel="- 全部 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{receiptRechargeStatisticsBean.receiptProductInfos}"
                                            var="receiptProductInfo"
                                            itemLabel="#{receiptProductInfo.name}"
                                            itemValue="#{receiptProductInfo.id}"/>
                                </p:selectOneMenu>
                            </div>

                            <div class="ui-g-1">
                                <p:outputLabel value="订单来源"/>
                            </div>
                            <div class="ui-g-5">
                                <p:selectOneMenu filter="true"
                                                 filterMatchMode="contains"
                                                 value="#{receiptRechargeStatisticsBean.$.sourceFrom}">
                                    <f:selectItem itemLabel="- 全部 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems
                                            value="#{receiptRechargeStatisticsBean.dictionaries[DictionaryCode.RECEIPT_ORDER_SOURCE_FROM]}"
                                            var="dic"
                                            itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>
                            </div>
                        </div>

                        <div class="ui-g-12" style="text-align: center">
                            <strong style="color: red;font-size: 18px">注意：由于单价、充值、余额没有来源之分，因此，为保证数据的计算正确，某些来源下的都会设置为0，只有一个来源有完整的数据</strong>
                        </div>

                        <div class="card">
                            <p:dataTable id="rechargeRecordDataTable"
                                         style="width: 100%"
                                         var="recharge"
                                         value="#{receiptRechargeStatisticsBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{receiptRechargeStatisticsBean.selectedRecords}"
                                         resizableColumns="true">

                                <p:column headerText="日期">
                                    <h:outputText value="#{recharge.date}">
                                        <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>

                                <p:column headerText="产品名称">
                                    <h:outputText value="#{recharge.productName}"/>
                                </p:column>

                                <p:column headerText="订单来源">
                                    <h:outputText value="#{recharge.sourceFrom == null ? '全部' :
                                    receiptRechargeStatisticsBean.translate(DictionaryCode.RECEIPT_ORDER_SOURCE_FROM,recharge.sourceFrom)}"/>
                                </p:column>

                                <p:column headerText="投递数">
                                    <h:outputText value="#{recharge.deliveryCount}"/>
                                </p:column>

                                <p:column headerText="消耗（元）">
                                    <h:outputText value="#{recharge.consumePrice}"/>
                                </p:column>

                                <p:column headerText="最新单价">
                                    <h:outputText value="#{recharge.unitPrice}"/>
                                </p:column>

                                <p:column headerText="充值（元）">
                                    <h:outputText value="#{recharge.rechargePrice}"/>
                                </p:column>

                                <p:column headerText="账户余额（元）">
                                    <h:outputText value="#{recharge.balance}"/>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
